//
//  NoteTableViewCell.m
//  HuaRun2
//
//  Created by admin on 17/8/29.
//  Copyright © 2017年 Sunny. All rights reserved.
//

#import "NoteTableViewCell.h"
#import "NoteModel.h"

@interface NoteTableViewCell ()
@property (nonatomic, strong) UIView * backView;

//名字
@property (nonatomic, strong) UILabel * nameLab;
//创建人
@property (nonatomic, strong) UILabel * createLab;
//最后修改人
@property (nonatomic, strong) UILabel * finalCreateLab;
////CRCView  私有备注
//@property (nonatomic, strong) CRCGroupFlagView * flagView;
//group
@property (nonatomic, strong) UILabel * groupLab;
//CRCFlag
@property (nonatomic, strong) UIButton * crcFlagView;

//时间
@property (nonatomic, strong) UILabel * timeLab;
////with
//@property (nonatomic, strong) UILabel * withLab;
//
////details
//@property (nonatomic, strong) UILabel * detailLab;
////location
//@property (nonatomic, strong) UILabel * locationLab;
////invited
//@property (nonatomic, strong) UILabel * invitedLab;

@end

@implementation NoteTableViewCell

#pragma mark - life cycle
- (void)dealloc {
    NSLog(@"%@ dealloc", [self class]);
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.contentView.backgroundColor = RGBA(249, 249, 249, 1);
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self viewInit];
        [self layoutInit];
    }
    return self;
}

- (void)viewInit {
    
    [self.contentView addSubview:self.backView];
    [self.contentView addSubview:self.nameLab];
    
//    [self.contentView addSubview:self.flagView];
    
    [self addSubview:self.crcFlagView];
    [self addSubview:self.groupLab];

    
    [self.contentView addSubview:self.createLab];
    [self.contentView addSubview:self.finalCreateLab];

    [self.contentView addSubview:self.timeLab];
//    [self.contentView addSubview:self.locationLab];
    
}

- (void)layoutInit {
    
    weakself(ws);
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.contentView).offset(kMargin10);
        make.right.mas_equalTo(ws.contentView).offset(-kMargin10);
        make.top.mas_equalTo(ws.contentView).offset(kMargin10);
        make.bottom.mas_equalTo(ws.contentView);
    }];
    
    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.backView.mas_left).offset(kMargin10);
        make.top.mas_equalTo(ws.backView).offset(kMargin10);
        make.right.mas_equalTo(ws.groupLab.mas_left).offset(-kMargin10);
    }];
    
    [self.groupLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(ws.crcFlagView.mas_left).offset(-kMargin10);
        make.centerY.mas_equalTo(ws.nameLab);
        make.width.mas_equalTo(80);
    }];
    
    [self.crcFlagView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(ws.backView.mas_right).offset(-kMargin10);
        make.centerY.mas_equalTo(ws.groupLab);
        make.size.mas_equalTo(CGSizeMake(10, 10));
    }];

    [self.createLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.nameLab);
        make.top.mas_equalTo(ws.nameLab.mas_bottom).offset(kMargin10);
        make.right.mas_equalTo(ws.backView).offset(-kMargin10);
    }];

    [self.finalCreateLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(ws.createLab);
        make.top.mas_equalTo(ws.createLab.mas_bottom).offset(kMargin10);
    }];

    CGFloat width = kMainScreenWidth - 10 * 4;

    [self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(ws.createLab);
        make.width.mas_equalTo(width);
        make.top.mas_equalTo(ws.finalCreateLab.mas_bottom).offset(kMargin10);
        make.bottom.mas_equalTo(ws.contentView).offset(-kMargin10);
    }];

}

#pragma mark - getter setter 
- (void)setNoteModel:(NoteModel *)noteModel {
    _noteModel = noteModel;

    _nameLab.text = [NSString showStringWithStr:noteModel.title];
    _createLab.text = [NSString stringWithFormat:@"%@    %@ %@",
                       NSLocalizedString(@"create_person", nil),
                       [NSString showStringWithStr:noteModel.createdName],
                       [NSString showStringWithStr:noteModel.createdDate]];
    
    _finalCreateLab.text = [NSString stringWithFormat:@"%@    %@ %@",                                                            NSLocalizedString(@"last_modify_person", nil),
                            [NSString showStringWithStr:noteModel.lastModifiedName],
                            [NSString showStringWithStr:noteModel.lastModifiedDate]];
    _timeLab.text = [NSString showStringWithStr:noteModel.body];

//    _crcFlagView.selected = [noteModel.isPrivate intValue] == 1;

}


- (UILabel *)nameLab {
    if (!_nameLab) {
        self.nameLab = [UILabel new];
        _nameLab.textAlignment = NSTextAlignmentLeft;
        _nameLab.font = kGeneralFontSize;
        _nameLab.textColor = [UIColor colorWithHex:@"3c3c3c"];
    }
    return _nameLab;
}

- (UIView *)backView {
    if (!_backView) {
        self.backView = [UIView new];
        _backView.backgroundColor = [UIColor whiteColor];
    }
    return _backView;
}

- (UILabel *)createLab {
    if (!_createLab) {
        self.createLab = [UILabel new];
        _createLab.textAlignment = NSTextAlignmentLeft;
        _createLab.font = kGeneralFontSize;
        _createLab.textColor = [UIColor colorWithHex:@"3c3c3c"];
        _createLab.text = NSLocalizedString(@"create_person", nil);
        
    }
    return _createLab;
}

- (UILabel *)finalCreateLab {
    if (!_finalCreateLab) {
        self.finalCreateLab = [UILabel new];
        _finalCreateLab.textAlignment = NSTextAlignmentLeft;
        _finalCreateLab.font = kGeneralFontSize;
        _finalCreateLab.textColor = [UIColor colorWithHex:@"3c3c3c"];
        _finalCreateLab.text = NSLocalizedString(@"last_modify_person", nil);
    }
    return _finalCreateLab;
}

- (UILabel *)timeLab {
    if (!_timeLab) {
        self.timeLab = [UILabel new];
        _timeLab.textAlignment = NSTextAlignmentLeft;
        _timeLab.font = kGeneralFontSize;
        _timeLab.textColor = [UIColor colorWithHex:@"3c3c3c"];
        _timeLab.numberOfLines = 0;
    }
    return _timeLab;
}


- (UILabel *)groupLab {
    if (!_groupLab) {
        self.groupLab = [UILabel new];
        _groupLab.textAlignment = NSTextAlignmentRight;
        _groupLab.font = kGeneralFontSize;
        _groupLab.textColor = [UIColor colorWithHex:@"3c3c3c"];
        _groupLab.text = NSLocalizedString(@"private_mark",nil);
        _groupLab.backgroundColor = kRandomColor;
        _groupLab.hidden = YES;
    }
    return _groupLab;
}

- (UIButton *)crcFlagView {
    if (!_crcFlagView) {
        self.crcFlagView = [UIButton new];
        [_crcFlagView setBackgroundImage:[UIImage imageNamed:@"私有备注未选中"]
                                forState:(UIControlStateNormal)];
        [_crcFlagView setBackgroundImage:[UIImage imageNamed:@"私有备注"]
                                forState:(UIControlStateSelected)];
        _crcFlagView.hidden = YES;
    }
    return _crcFlagView;
}
@end
